package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
)

func responseSize(url string, channel chan int) {
	fmt.Println("Getting", url)
	response, err := http.Get(url)
	if err != nil {
		log.Fatal(err)
	}
	defer func(Body io.ReadCloser) {
		err := Body.Close()
		if err != nil {
			log.Fatal(err)
		}
	}(response.Body)

	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		log.Fatal(err)
	}
	// fmt.Println(string(body))
	// fmt.Println(len(body))
	channel <- len(body)
}

func main() {
	sise := make(chan int)
	urls := []string{
		"https://example.com/",
		"https://baidu.com/",
		"https://gitee.com/",
	}
	for _, url := range urls {
		go responseSize(url, sise)
	}
	for i := 0; i < len(urls); i++ {
		fmt.Println(<-sise)
	}
}
